/*
@(#)WechatpayConfig   2024-09-23
 
Copyright (c) 2011-2024 杭州湖畔网络技术有限公司 
保留所有权利 
本软件为杭州湖畔网络技术有限公司所有及包含机密信息，须遵守其相关许可证条款进行使用。
Copyright (c) 2011-2024 HUPUN Network Technology CO.,LTD.
All rights reserved.
This software is the confidential and proprietary information of HUPUN
Network Technology CO.,LTD("Confidential Information").  You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into with HUPUN.
Website：http://www.hupun.com
*/
package org.obp.pay.third.wechat.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: Jackey 2024/9/23
 */
@Data
@Component
public class WechatpayConfig implements InitializingBean {

    /**
     * AppId - MA
     */
    @Value("${pay.wechat.appId_ma}")
    private String appId_ma = "";
    /**
     * AppId - APP
     */
    @Value("${pay.wechat.appId_app}")
    private String appId_app = "";

    /**
     * 商户号
     */
    @Value("${pay.wechat.merchantId}")
    private String merchantId = "";
    /**
     * 商户API私钥
     */
    @Value("${pay.wechat.privateKey}")
    private String privateKey = "";
    /**
     * 商户证书序列号
     */
    @Value("${pay.wechat.merchantSerialNumber}")
    private String merchantSerialNumber = "";
    /**
     * 商户APIV3密钥
     */
    @Value("${pay.wechat.apiV3Key}")
    private String apiV3Key = "";
    /**
     * 商户主域名
     */
    @Value("${pay.wechat.domain}")
    private String domain = "";
    /**
     * 支付通知地址
     */
    @Value("${pay.wechat.payNotifyUrl}")
    private String payNotifyUrl = "/v1/payment/pay/notify/wechatpay";
    /**
     * 退款通知地址
     */
    @Value("${pay.wechat.refundNotifyUrl}")
    private String refundNotifyUrl = "/v1/payment/refund/notify/wechatpay";
    /**
     * 订单支付过期（分钟）
     */
    @Value("${pay.wechat.expiredMinutes}")
    private Integer expiredMinutes = 15;

    /**
     * 使用自动更新平台证书的 RSA 配置
     * 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
     */
    private RSAAutoCertificateConfig wxPayConfig;

    @Override
    public void afterPropertiesSet() {
        try {
            wxPayConfig = new RSAAutoCertificateConfig.Builder()
                    .merchantId(merchantId)
                    .privateKey(privateKey)
                    .merchantSerialNumber(merchantSerialNumber)
                    .apiV3Key(apiV3Key)
                    .build();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}